--Creating the Logon_Trigger to get the logon activity of SYSDBA Users.
CREATE or REPLACE TRIGGER
   logon_trigger
AFTER LOGON ON DATABASE
DECLARE
sysuser VARCHAR2(20);

--Creating the cursor for getting the list of users from v$pwfile_users who are SYSDBA
CURSOR sysrole is
SELECT username
	FROM v$pwfile_users
	WHERE user=sys_context('userenv','session_user') AND SYSDBA='TRUE';

BEGIN
	OPEN sysrole;
	LOOP
		--Fetching the cursor results into the variable.
		FETCH sysrole INTO sysuser;
		EXIT WHEN sysrole%NOTFOUND;

		--Matching if the logon user is in the list of v$pwfile_users and are SYSDBA
		IF user=sysuser then
			--Inserting the data into user_action_log
			INSERT INTO user_action_log
				(username,
				start_time,
				end_time
				)
				VALUES(sysuser,
						sysdate,
						null);
		END IF;
	END LOOP;
END;
/
